x=eval(input())
y=eval(input())
for i in range(x,y+1):
    for j in range(2,i):
        if i%j==0:
            break
    else:
        z=int(str(i)[::-1])
        for k in range(2,z):
            if z%k==0:
                break
        else:
            if i!=z:
                print(i)
            

